package com.openbravo.pos.panels.navigator;


import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreeCellRenderer;
import cn.ekuma.data.dao.I_DataLogic;
import cn.ekuma.data.dao.user.tree.BrowsableEditableTreeDataModel;
import com.openbravo.bean.erp.OperationProductCategory;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.JDragAbleTreeNavigator;
import com.openbravo.data.gui.TreeCellRendererBasic;
import com.openbravo.data.loader.IRenderString;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.data.user.EditorRecordAdapter;
import com.openbravo.pos.panels.navigator.event.OperationProductCategoryChangedListener;

public class JOperationProductCategoryNavigator extends JDragAbleTreeNavigator<OperationProductCategory>{

	public JOperationProductCategoryNavigator(I_DataLogic dataLogic) {
		super(new BrowsableEditableTreeDataModel(dataLogic,OperationProductCategory.class,null,new EditorRecordAdapter<OperationProductCategory>(),new DirtyManager()));
	    setCellRenderer(getTreeCellRenderer());
	}

	public void loadData() throws BasicException{
			m_bd.loadData();
	}

	@Override
	public void valueChanged(TreeSelectionEvent evt) {
		super.valueChanged(evt);
		for(OperationProductCategoryChangedListener l:listenerList.getListeners(OperationProductCategoryChangedListener.class))
			l.valueSelectChanged((OperationProductCategory) m_bd.getSelectedObj().getCategory());
	}

	public void addOperationProductCategoryChangedListener(OperationProductCategoryChangedListener l){
		listenerList.add(OperationProductCategoryChangedListener.class, l);
	}
	
	public void removeOperationProductCategoryChangedListener(OperationProductCategoryChangedListener l){
		listenerList.remove(OperationProductCategoryChangedListener.class, l);
	}
	
	public TreeCellRenderer getTreeCellRenderer() {
        return new TreeCellRendererBasic(new IRenderString<OperationProductCategory>(){
            public String getRenderString(OperationProductCategory value) {
               return value.getName();
            }
        });
    }
}
